In [3]:
# -*- coding: utf-8 -*-
#journals.py
"""Journals are particular kind of publication.

They have different publications in them by different authors.
Journals are periodical. Journals are made by publishers. Authors publish
in journals. Journals contain articles. Journals have associated editors.
Journals have.

There is a limited number of journals we have interest. For know we can 
separated two groups of journals. First group of journals contain 
interesting theoretical claims that we base our research on. Second 
group of journals are mor einterested as a source of data.

First group consist of around 50 journals.
Second group is way larger.
"""

class Journal():
    __self__ = ''
    editors = []
    publications = []
    volumes = None
    established = 'timestamp'
    authors_who_published = []
    journals_that_cited_this_journal = []
    
s4 = Journal


import pandas as pd
url = r'd:\Documents\GitHub\disciplines\disciplines\data\xlsx\sts books and journals.xlsx'
df = pd.read_excel(url, header=None )
df.columns = ['name', 'url']

In [4]:
# -*- coding: utf-8 -*-
#syllabi.py

source_url = r'http://www.4sonline.org/resources/syllabi'
url = r'd:\Documents\GitHub\disciplines\disciplines\data\xlsx\sts syllabi.xlsx'
df = pd.read_excel(url, header=0 )

In [5]:
df


Out[5]:
Professor Topic Level Department/Program Language url
0 Akera1  Information Technology U Science & Technology Studies English NaN
1 .doc .pdf NaN NaN NaN NaN NaN
2 Akera2 Science & Technology Studies U Science & Technology Studies English NaN
3 .doc .pdf NaN NaN NaN NaN NaN
4 Balmer1 Science & Technology Policy U Science & Technology Studies English http://www.4sonline.org/syllabi/Balmer1.doc#
5 Balmer2 Genetics and Society U Science & Technology Studies English http://www.4sonline.org/syllabi/Balmer.doc#
6 Chang1 Philosophy of Science U Science & Technology Studies English http://www.4sonline.org/syllabi/chang1.doc#
7 Chang2 Hist & Phil of Physical Sciences U Science & Technology Studies English NaN
8 Clarke (1) Gender & Race G Sociology English http://www.4sonline.org/syllabi/Clarke1.doc#
9 Clarke (2) STS & Medicine G Sociology English http://www.4sonline.org/syllabi/AClarke_07_STS...
10 Clarke & Anderson Medicine G Sociology English http://www.4sonline.org/syllabi/Clarke2.doc#
11 Delborne Science, Technology, and Medicine in Society G Science & Technology Studies English http://www.4sonline.org/syllabi/Delborne901.pdf#
12 Fox Gender & Race U Science & Technology Studies English http://www.4sonline.org/syllabi/Fox--syllabus....
13 Gregory1 History of Science U Science & Technology Studies English http://www.4sonline.org/syllabi/Gregory1.doc#
14 Gregory2 Scientific Revolution U Science & Technology Studies English NaN
15 Gregory3 Magic to Sciences U Science & Technology Studies English NaN
16 Guay Technology Studies U Sociology French http://www.4sonline.org/syllabi/Guay.doc#
17 Guston Science & Technology Policy G Public Policy English http://www.4sonline.org/syllabi/Guston.dot#
18 Hausman (1) Medicine & Anthropology U Anthropology English http://www.4sonline.org/syllabi/Hausman1.htm#
19 Hausman (2) Anthropology of the Body and the Subject U, G Anthropology English http://www.4sonline.org/syllabi/Hausman2.htm#
20 Hess Science & Technology Studies U Science & Technology Studies English http://www.4sonline.org/syllabi/Hess.doc#
21 Hess (2) Science & Social Theory U Science & Technology Studies English http://www.4sonline.org/syllabi/HessGradSTS201...
22 Karvonen (1) Nanotechnology U Science & Technology Studies English http://www.4sonline.org/syllabi/Karvonen1.pdf#
23 Karvonen (2) Engineering Ethics U Science & Technology Studies English http://www.4sonline.org/syllabi/Karvonen2.pdf#
24 Klawiter Science & Technology Studies G Science & Technology Studies English http://www.4sonline.org/syllabi/klawiter.doc#
25 Leydesdorff (1) Technology Studies G Science & Technology Studies English http://www.4sonline.org/syllabi/Leydesdorff1.htm#
26 Leydesdorff (2) Sociology of Knowledge G Science & Technology Studies English http://www.4sonline.org/syllabi/Leydesdorff2.htm#
27 Mitcham Science& Technology Studies G Science& Technology Studies English http://www.4sonline.org/syllabi/Mitcham.htm#
28 Monahan (1) Technology Studies U Justice Studies English http://www.4sonline.org/syllabi/Monahan.htm#
29 Monahan (2) Technology & Globalization G Justice Studies English http://www.4sonline.org/syllabi/Monahan.htm#
30 Monahan (3) Technology of Surveillance  U Justice Studies English http://www.4sonline.org/syllabi/Monahan3.pdf#
31 Monahan (4) Globalization & Technology G Justice Studies English http://www.4sonline.org/syllabi/Monahan4.pdf#
32 Nelson Cyborg Anthropology U Anthropology English http://www.4sonline.org/syllabi/Nelson.doc#
33 Pielke (1) Science & Technology Policy G Science & Technology Studies English http://www.4sonline.org/syllabi/Pielke1.htm#
34 Pielke (2) Science & Environment G Science & Technology Studies English http://www.4sonline.org/syllabi/Pielke2.htm#
35 Pinch STS Intro U Sociology English http://www.4sonline.org/syllabi/TPinch05_STS.doc#
36 Pinch (2) STS and Music U Sociology English http://www.4sonline.org/syllabi/TPinch06_STS_M...
37 Pollock Intro to STS U Anthropology English http://www.4sonline.org/syllabi/PollockIntroST...
38 Rehg Philosophy & Technology G Philosophy English http://www.4sonline.org/syllabi/WRehg06_Phil_T...
39 Rosa (1) Technology Studies U Sociology English http://www.4sonline.org/syllabi/Rosa1.doc#
40 Rosa (2) Risk G Sociology English http://www.4sonline.org/syllabi/Rosa2.doc#
41 Scheiderer Body U Other Interdisciplinary English http://www.4sonline.org/syllabi/Scheiderer.htm#
42 Sonnenfeld Technology Studies U Sociology English http://www.4sonline.org/syllabi/soc430/index.htm#
43 Tang Science & Technology Studies U Sociology English http://www.4sonline.org/syllabi/Tangsyllabus.doc#
44 Taylor (1) Science & Technology Studies U Anthropology English http://www.4sonline.org/syllabi/Taylor1.doc#
45 Taylor (2) Medicine U Anthropology English http://www.4sonline.org/syllabi/taylor2.doc#
46 Taylor (3) Medicine U Anthropology English http://www.4sonline.org/syllabi/taylor3.doc#
47 Zehr (1) Science & Society U Other Interdisciplinary English http://www.4sonline.org/syllabi/Zehr1.doc#
48 Zehr (2) Sociology of the Environment G Sociology English http://www.4sonline.org/syllabi/Zehr2.doc#

In [12]:
#system pip install mechanize
#system pip install python-docx
import mechanize
import docx

br = mechanize.Browser()
haha = br.open('http://www.4sonline.org/syllabi/Balmer1.doc')
document = docx.Document(haha.content)
#document.paragraphs


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-12-1c3e6f98b7a0> in <module>()
      6 br = mechanize.Browser()
      7 haha = br.open('http://www.4sonline.org/syllabi/Balmer1.doc')
----> 8 document = docx.Document(haha.content)
      9 #document.paragraphs

C:\c\envs\p2\lib\site-packages\mechanize\_response.pyc in __getattr__(self, name)
     97         wrapped = self.__dict__.get("wrapped")
     98         if wrapped:
---> 99             return getattr(wrapped, name)
    100 
    101         return getattr(self.__class__, name)

AttributeError: closeable_response instance has no attribute 'content'

Delarative


In [1]:
#sqlalchemy
from sqlalchemy import *
from sqlalchemy import create_engine, Table, Column, Integer, String, ForeignKey
from sqlalchemy.orm import relationship, backref
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.engine.url import URL

DeclarativeBase = declarative_base()

engine = create_engine('sqlite:///:memory:', echo=True)

#metadata = MetaData()

class Disciplines(DeclarativeBase):
    """Disciplines"""
    __tablename__ = "disciplines"

    id = Column(Integer, primary_key=True)
    name = Column('name', String)
    description = Column('description', String, nullable=True)
    link = Column('link', String, nullable=True)
#    subdisciplines = relationship('subdisciplines', backref="disciplines")
#    classifications = relationship('classifications', backref="disciplines")
    
class Classifications(DeclarativeBase):
    """Classifications"""
    __tablename__ = "classifications"

    id = Column(Integer, primary_key=True)
    name = Column('name', String)
    description = Column('description', String, nullable=True)
    link = Column('link', String, nullable=True)
#    author = relationship('persons', backref="classifications")

class Learned_societies(DeclarativeBase):
    """Learned_societies"""
    __tablename__ = "learned societies"

    id = Column(Integer, primary_key=True)
    name = Column('name', String)
    description = Column('description', String, nullable=True)
    link = Column('link', String, nullable=True)
#    members = relationship('persons', ForeignKey('learned_societies'))

class Persons(DeclarativeBase):
    """Persons"""
    __tablename__ = "persons"

    id = Column(Integer, primary_key=True)
    name = Column('name', String)
    first_name = Column('first_name', String)
    last_name = Column('last_name', String)
    link = Column('link', String, nullable=True)
#    learned_societies = relationship('persons', ForeignKey('persons.id'))
    
class Concepts(DeclarativeBase):
    """Concepts"""
    __tablename__ = "concepts"

    id = Column(Integer, primary_key=True)
    name = Column('name', String)
    definition = Column('definition', String, nullable=True)
    link = Column('link', String, nullable=True)
#    definition = relationship('definitions', backref="parent")
    
class Definitions(DeclarativeBase):
    """Definitions"""
    __tablename__ = "definitions"

    id = Column(Integer, primary_key=True)
    name = Column('name', String)

class Publications(DeclarativeBase):
    """Publications"""
    __tablename__ = "publications"

    id = Column(Integer, primary_key=True)
    title = Column('title', String)
    description = Column('description', String, nullable=True)
    link = Column('link', String, nullable=True)
    original_price = Column('original_price', String, nullable=True)
    price = Column('price', String, nullable=True)
    
DeclarativeBase.metadata.create_all(engine)


2014-09-03 14:44:09,887 INFO sqlalchemy.engine.base.Engine SELECT CAST('test plain returns' AS VARCHAR(60)) AS anon_1
INFO:sqlalchemy.engine.base.Engine:SELECT CAST('test plain returns' AS VARCHAR(60)) AS anon_1
2014-09-03 14:44:09,888 INFO sqlalchemy.engine.base.Engine ()
INFO:sqlalchemy.engine.base.Engine:()
2014-09-03 14:44:09,891 INFO sqlalchemy.engine.base.Engine SELECT CAST('test unicode returns' AS VARCHAR(60)) AS anon_1
INFO:sqlalchemy.engine.base.Engine:SELECT CAST('test unicode returns' AS VARCHAR(60)) AS anon_1
2014-09-03 14:44:09,891 INFO sqlalchemy.engine.base.Engine ()
INFO:sqlalchemy.engine.base.Engine:()
2014-09-03 14:44:09,895 INFO sqlalchemy.engine.base.Engine PRAGMA table_info("concepts")
INFO:sqlalchemy.engine.base.Engine:PRAGMA table_info("concepts")
2014-09-03 14:44:09,897 INFO sqlalchemy.engine.base.Engine ()
INFO:sqlalchemy.engine.base.Engine:()
2014-09-03 14:44:09,898 INFO sqlalchemy.engine.base.Engine PRAGMA table_info("learned societies")
INFO:sqlalchemy.engine.base.Engine:PRAGMA table_info("learned societies")
2014-09-03 14:44:09,900 INFO sqlalchemy.engine.base.Engine ()
INFO:sqlalchemy.engine.base.Engine:()
2014-09-03 14:44:09,901 INFO sqlalchemy.engine.base.Engine PRAGMA table_info("disciplines")
INFO:sqlalchemy.engine.base.Engine:PRAGMA table_info("disciplines")
2014-09-03 14:44:09,901 INFO sqlalchemy.engine.base.Engine ()
INFO:sqlalchemy.engine.base.Engine:()
2014-09-03 14:44:09,904 INFO sqlalchemy.engine.base.Engine PRAGMA table_info("persons")
INFO:sqlalchemy.engine.base.Engine:PRAGMA table_info("persons")
2014-09-03 14:44:09,907 INFO sqlalchemy.engine.base.Engine ()
INFO:sqlalchemy.engine.base.Engine:()
2014-09-03 14:44:09,907 INFO sqlalchemy.engine.base.Engine PRAGMA table_info("publications")
INFO:sqlalchemy.engine.base.Engine:PRAGMA table_info("publications")
2014-09-03 14:44:09,908 INFO sqlalchemy.engine.base.Engine ()
INFO:sqlalchemy.engine.base.Engine:()
2014-09-03 14:44:09,911 INFO sqlalchemy.engine.base.Engine PRAGMA table_info("classifications")
INFO:sqlalchemy.engine.base.Engine:PRAGMA table_info("classifications")
2014-09-03 14:44:09,911 INFO sqlalchemy.engine.base.Engine ()
INFO:sqlalchemy.engine.base.Engine:()
2014-09-03 14:44:09,914 INFO sqlalchemy.engine.base.Engine PRAGMA table_info("definitions")
INFO:sqlalchemy.engine.base.Engine:PRAGMA table_info("definitions")
2014-09-03 14:44:09,914 INFO sqlalchemy.engine.base.Engine ()
INFO:sqlalchemy.engine.base.Engine:()
2014-09-03 14:44:09,917 INFO sqlalchemy.engine.base.Engine 
CREATE TABLE concepts (
	id INTEGER NOT NULL, 
	name VARCHAR, 
	definition VARCHAR, 
	link VARCHAR, 
	PRIMARY KEY (id)
)


INFO:sqlalchemy.engine.base.Engine:
CREATE TABLE concepts (
	id INTEGER NOT NULL, 
	name VARCHAR, 
	definition VARCHAR, 
	link VARCHAR, 
	PRIMARY KEY (id)
)


2014-09-03 14:44:09,918 INFO sqlalchemy.engine.base.Engine ()
INFO:sqlalchemy.engine.base.Engine:()
2014-09-03 14:44:09,921 INFO sqlalchemy.engine.base.Engine COMMIT
INFO:sqlalchemy.engine.base.Engine:COMMIT
2014-09-03 14:44:09,926 INFO sqlalchemy.engine.base.Engine 
CREATE TABLE "learned societies" (
	id INTEGER NOT NULL, 
	name VARCHAR, 
	description VARCHAR, 
	link VARCHAR, 
	PRIMARY KEY (id)
)


INFO:sqlalchemy.engine.base.Engine:
CREATE TABLE "learned societies" (
	id INTEGER NOT NULL, 
	name VARCHAR, 
	description VARCHAR, 
	link VARCHAR, 
	PRIMARY KEY (id)
)


2014-09-03 14:44:09,927 INFO sqlalchemy.engine.base.Engine ()
INFO:sqlalchemy.engine.base.Engine:()
2014-09-03 14:44:09,930 INFO sqlalchemy.engine.base.Engine COMMIT
INFO:sqlalchemy.engine.base.Engine:COMMIT
2014-09-03 14:44:09,931 INFO sqlalchemy.engine.base.Engine 
CREATE TABLE disciplines (
	id INTEGER NOT NULL, 
	name VARCHAR, 
	description VARCHAR, 
	link VARCHAR, 
	PRIMARY KEY (id)
)


INFO:sqlalchemy.engine.base.Engine:
CREATE TABLE disciplines (
	id INTEGER NOT NULL, 
	name VARCHAR, 
	description VARCHAR, 
	link VARCHAR, 
	PRIMARY KEY (id)
)


2014-09-03 14:44:09,934 INFO sqlalchemy.engine.base.Engine ()
INFO:sqlalchemy.engine.base.Engine:()
2014-09-03 14:44:09,936 INFO sqlalchemy.engine.base.Engine COMMIT
INFO:sqlalchemy.engine.base.Engine:COMMIT
2014-09-03 14:44:09,937 INFO sqlalchemy.engine.base.Engine 
CREATE TABLE persons (
	id INTEGER NOT NULL, 
	name VARCHAR, 
	first_name VARCHAR, 
	last_name VARCHAR, 
	link VARCHAR, 
	PRIMARY KEY (id)
)


INFO:sqlalchemy.engine.base.Engine:
CREATE TABLE persons (
	id INTEGER NOT NULL, 
	name VARCHAR, 
	first_name VARCHAR, 
	last_name VARCHAR, 
	link VARCHAR, 
	PRIMARY KEY (id)
)


2014-09-03 14:44:09,938 INFO sqlalchemy.engine.base.Engine ()
INFO:sqlalchemy.engine.base.Engine:()
2014-09-03 14:44:09,940 INFO sqlalchemy.engine.base.Engine COMMIT
INFO:sqlalchemy.engine.base.Engine:COMMIT
2014-09-03 14:44:09,941 INFO sqlalchemy.engine.base.Engine 
CREATE TABLE publications (
	id INTEGER NOT NULL, 
	title VARCHAR, 
	description VARCHAR, 
	link VARCHAR, 
	original_price VARCHAR, 
	price VARCHAR, 
	PRIMARY KEY (id)
)


INFO:sqlalchemy.engine.base.Engine:
CREATE TABLE publications (
	id INTEGER NOT NULL, 
	title VARCHAR, 
	description VARCHAR, 
	link VARCHAR, 
	original_price VARCHAR, 
	price VARCHAR, 
	PRIMARY KEY (id)
)


2014-09-03 14:44:09,944 INFO sqlalchemy.engine.base.Engine ()
INFO:sqlalchemy.engine.base.Engine:()
2014-09-03 14:44:09,946 INFO sqlalchemy.engine.base.Engine COMMIT
INFO:sqlalchemy.engine.base.Engine:COMMIT
2014-09-03 14:44:09,947 INFO sqlalchemy.engine.base.Engine 
CREATE TABLE classifications (
	id INTEGER NOT NULL, 
	name VARCHAR, 
	description VARCHAR, 
	link VARCHAR, 
	PRIMARY KEY (id)
)


INFO:sqlalchemy.engine.base.Engine:
CREATE TABLE classifications (
	id INTEGER NOT NULL, 
	name VARCHAR, 
	description VARCHAR, 
	link VARCHAR, 
	PRIMARY KEY (id)
)


2014-09-03 14:44:09,950 INFO sqlalchemy.engine.base.Engine ()
INFO:sqlalchemy.engine.base.Engine:()
2014-09-03 14:44:09,950 INFO sqlalchemy.engine.base.Engine COMMIT
INFO:sqlalchemy.engine.base.Engine:COMMIT
2014-09-03 14:44:09,954 INFO sqlalchemy.engine.base.Engine 
CREATE TABLE definitions (
	id INTEGER NOT NULL, 
	name VARCHAR, 
	PRIMARY KEY (id)
)


INFO:sqlalchemy.engine.base.Engine:
CREATE TABLE definitions (
	id INTEGER NOT NULL, 
	name VARCHAR, 
	PRIMARY KEY (id)
)


2014-09-03 14:44:09,957 INFO sqlalchemy.engine.base.Engine ()
INFO:sqlalchemy.engine.base.Engine:()
2014-09-03 14:44:09,957 INFO sqlalchemy.engine.base.Engine COMMIT
INFO:sqlalchemy.engine.base.Engine:COMMIT

In [4]:
from sqlalchemy.orm import sessionmaker
Session = sessionmaker(bind=engine)
session = Session()


tables = [Disciplines, Persons, Definitions, Publications, Learned_societies]
for x in tables:
    q = session.query(x)
    print q.column_descriptions


[{'aliased': False, 'expr': <class '__main__.Disciplines'>, 'type': <class '__main__.Disciplines'>, 'name': 'Disciplines'}]
[{'aliased': False, 'expr': <class '__main__.Persons'>, 'type': <class '__main__.Persons'>, 'name': 'Persons'}]
[{'aliased': False, 'expr': <class '__main__.Definitions'>, 'type': <class '__main__.Definitions'>, 'name': 'Definitions'}]
[{'aliased': False, 'expr': <class '__main__.Publications'>, 'type': <class '__main__.Publications'>, 'name': 'Publications'}]
[{'aliased': False, 'expr': <class '__main__.Learned_societies'>, 'type': <class '__main__.Learned_societies'>, 'name': 'Learned_societies'}]

In [16]:



2014-09-03 14:00:50,526 INFO sqlalchemy.engine.base.Engine BEGIN (implicit)
INFO:sqlalchemy.engine.base.Engine:BEGIN (implicit)
2014-09-03 14:00:50,529 INFO sqlalchemy.engine.base.Engine INSERT INTO disciplines (name, description, link, original_price, price) VALUES (?, ?, ?, ?, ?)
INFO:sqlalchemy.engine.base.Engine:INSERT INTO disciplines (name, description, link, original_price, price) VALUES (?, ?, ?, ?, ?)
2014-09-03 14:00:50,530 INFO sqlalchemy.engine.base.Engine ('user1', None, None, None, None)
INFO:sqlalchemy.engine.base.Engine:('user1', None, None, None, None)
2014-09-03 14:00:50,532 INFO sqlalchemy.engine.base.Engine INSERT INTO disciplines (name, description, link, original_price, price) VALUES (?, ?, ?, ?, ?)
INFO:sqlalchemy.engine.base.Engine:INSERT INTO disciplines (name, description, link, original_price, price) VALUES (?, ?, ?, ?, ?)
2014-09-03 14:00:50,533 INFO sqlalchemy.engine.base.Engine ('user2', None, None, None, None)
INFO:sqlalchemy.engine.base.Engine:('user2', None, None, None, None)
2014-09-03 14:00:50,536 INFO sqlalchemy.engine.base.Engine COMMIT
INFO:sqlalchemy.engine.base.Engine:COMMIT

In [15]:
discipline = Disciplines(name='philosophy', description='The description')
discipline1 = Disciplines(name='sociology')
session.add(discipline)
session.add(discipline1)
session.commit()

session.add_all([Disciplines(name='physics', description='The description')])
session.commit()


2014-09-03 14:59:48,651 INFO sqlalchemy.engine.base.Engine BEGIN (implicit)
INFO:sqlalchemy.engine.base.Engine:BEGIN (implicit)
2014-09-03 14:59:48,653 INFO sqlalchemy.engine.base.Engine INSERT INTO disciplines (name, description, link) VALUES (?, ?, ?)
INFO:sqlalchemy.engine.base.Engine:INSERT INTO disciplines (name, description, link) VALUES (?, ?, ?)
2014-09-03 14:59:48,654 INFO sqlalchemy.engine.base.Engine ('physics', 'The description', None)
INFO:sqlalchemy.engine.base.Engine:('physics', 'The description', None)
2014-09-03 14:59:48,655 INFO sqlalchemy.engine.base.Engine INSERT INTO disciplines (name, description, link) VALUES (?, ?, ?)
INFO:sqlalchemy.engine.base.Engine:INSERT INTO disciplines (name, description, link) VALUES (?, ?, ?)
2014-09-03 14:59:48,657 INFO sqlalchemy.engine.base.Engine ('philosophy', 'The description', None)
INFO:sqlalchemy.engine.base.Engine:('philosophy', 'The description', None)
2014-09-03 14:59:48,658 INFO sqlalchemy.engine.base.Engine INSERT INTO disciplines (name, description, link) VALUES (?, ?, ?)
INFO:sqlalchemy.engine.base.Engine:INSERT INTO disciplines (name, description, link) VALUES (?, ?, ?)
2014-09-03 14:59:48,661 INFO sqlalchemy.engine.base.Engine ('sociology', None, None)
INFO:sqlalchemy.engine.base.Engine:('sociology', None, None)
2014-09-03 14:59:48,661 INFO sqlalchemy.engine.base.Engine COMMIT
INFO:sqlalchemy.engine.base.Engine:COMMIT
2014-09-03 14:59:48,664 INFO sqlalchemy.engine.base.Engine BEGIN (implicit)
INFO:sqlalchemy.engine.base.Engine:BEGIN (implicit)
2014-09-03 14:59:48,665 INFO sqlalchemy.engine.base.Engine INSERT INTO disciplines (name, description, link) VALUES (?, ?, ?)
INFO:sqlalchemy.engine.base.Engine:INSERT INTO disciplines (name, description, link) VALUES (?, ?, ?)
2014-09-03 14:59:48,665 INFO sqlalchemy.engine.base.Engine ('physics', 'The description', None)
INFO:sqlalchemy.engine.base.Engine:('physics', 'The description', None)
2014-09-03 14:59:48,667 INFO sqlalchemy.engine.base.Engine COMMIT
INFO:sqlalchemy.engine.base.Engine:COMMIT

In [35]:
from sqlalchemy.sql import expression
expression.delete(Disciplines, whereclause='name' is 'philosophy')


Out[35]:
<sqlalchemy.sql.dml.Delete object at 0x0000000004825438>

In [41]:
from sqlalchemy import update
Disciplines.update().values(
        name=select(['philosophy']).\
                where(addresses.c.user_id==users.c.id).\
                as_scalar())


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-41-eef6292d0787> in <module>()
      1 from sqlalchemy import update
----> 2 Disciplines.update().values(
      3         name=select(['philosophy']).\
      4                 where(addresses.c.user_id==users.c.id).\
      5                 as_scalar())

AttributeError: type object 'Disciplines' has no attribute 'update'

In [47]:
from sqlalchemy.sql import Insert
Insert(table, values=None, inline=False, bind=None, prefixes=None, returning=None, **kwargs)


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-47-ada9e3c366a3> in <module>()
      1 from sqlalchemy.sql import Insert
      2 
----> 3 session.Insert(table, values=None, inline=False, bind=None, prefixes=None, returning=None, **kwargs)

AttributeError: 'Session' object has no attribute 'Insert'

Non delcarative sqlalchemy


In [64]:
engine = create_engine('sqlite:///:memory:')

metadata = MetaData()

user = Table('user', metadata,
    Column('user_id', Integer, primary_key = True),
    Column('user_name', String(16), nullable = False),
    Column('email_address', String(60), key='email'),
    Column('password', String(20), nullable = False)
)

user_prefs = Table('user_prefs', metadata,
    Column('pref_id', Integer, primary_key=True),
    Column('user_id', Integer, ForeignKey("user.user_id"), nullable=False),
    Column('pref_name', String(40), nullable=False),
    Column('pref_value', String(100))
)

metadata.create_all(engine)

for t in metadata.sorted_tables:
    print t.name


user
user_prefs

RDFLIB

With some titles


In [16]:
url = r'd:\Desktop\medline11n0653.nq'

In [17]:
from rdflib import ConjunctiveGraph, URIRef, Namespace

In [18]:
g = ConjunctiveGraph()
data = open(url, "rb")


---------------------------------------------------------------------------
IOError                                   Traceback (most recent call last)
<ipython-input-18-cecc23ee99a8> in <module>()
      1 g = ConjunctiveGraph()
----> 2 data = open(url, "rb")

IOError: [Errno 2] No such file or directory: 'd:\\Desktop\\medline11n0653.nq'

In [19]:
g.parse(data, format="nquads")


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-19-30755f49d69b> in <module>()
----> 1 g.parse(data, format="nquads")

NameError: name 'data' is not defined

In [18]:
len(g)
g?

In [29]:
count = 0
for x,y,z in g:
    count += 1
    print x, y, z
    if count == 50:
        break


Nf48e73c06f2a46399e79f9ef206d0dd2 http://www.w3.org/2000/01/rdf-schema#label medline11n0001
http://purl.org/okfn/medline/medline11n0001/23396 http://purl.org/dc/terms/source PubMed-not-MEDLINE
Nda4170a01f854f09bead2a5883303e6d http://www.w3.org/2006/time#inXSDDateTime 2011-05-08T14:41:06+00:00
http://www.ncbi.nlm.nih.gov/pubmed/17781855 http://purl.org/dc/terms/isPartOf N12ebe64ddb934606ab0017200afa6d1d
http://www.ncbi.nlm.nih.gov/pubmed/17756121 http://purl.org/dc/terms/creator N3717b9f6ef4247e58838b5fa68f35f12
http://www.ncbi.nlm.nih.gov/pubmed/17731640 http://purl.org/dc/terms/published 1892-15
http://www.ncbi.nlm.nih.gov/pubmed/17806432 http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://purl.org/ontology/bibo/AcademicArticle
http://www.ncbi.nlm.nih.gov/pubmed/17232100 http://purl.org/dc/terms/isPartOf N05c7645ac2ff4668b158241c6a2d8417
N22b2477408544300b76cb656e48f5e62 http://purl.org/dc/terms/spatial United States
N42c82b7e8b1b452aa36b0782bca73861 http://purl.org/net/opmv/ns#used Nc52a4af4ebc543bd8838b53c7dacfc17
Ndb2a222646984b5ea17aafd93fa862c4 http://www.w3.org/2000/01/rdf-schema#label medline11n0001
http://www.ncbi.nlm.nih.gov/pubmed/17757405 http://purl.org/dc/terms/isPartOf N3d1dcbf883d44fcb80ffbec9d3958986
N29aba2d9928c4211a4518b9246390f47 http://purl.org/net/opmv/ns#wasControlledBy http://river.styx.org/ww/foaf#me
http://purl.org/okfn/medline/medline11n0001/11818 http://purl.org/dc/terms/source PubMed-not-MEDLINE
N5324fc5251524044a0116b0aec942df2 http://xmlns.com/foaf/0.1/name Bell, A N
Nd3d5733b694d438ca782ae2f109d7171 http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://www.w3.org/2006/time#Instant
N64d1597c6f904485b2835cef005638aa http://purl.org/ontology/bibo/volume 4
http://purl.org/okfn/medline/medline11n0001/21835 http://purl.org/dc/terms/source PubMed-not-MEDLINE
Nc700aa389ccd4078b26d4deb359517e3 http://purl.org/net/opmv/ns#wasControlledBy http://river.styx.org/ww/foaf#me
http://www.ncbi.nlm.nih.gov/pubmed/17232056 http://purl.org/dc/terms/title Notes on the Development and Variations of the Atlas.
N060511d6b770439c97477c2a3ad48a63 http://www.w3.org/2000/01/rdf-schema#label medline11n0001
N95ba409b7fd845bf9e32207955016648 http://xmlns.com/foaf/0.1/familyName Curry
http://purl.org/okfn/medline/medline11n0001/16443 http://purl.org/dc/terms/issued 2010-07-02
Nab924b364ff4492ca77cf8ea01c56178 http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://purl.org/ontology/bibo/Issue
Neeea3d8074db49b693ca1597a0b6280f http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://purl.org/ontology/bibo/Issue
N3f3b1d61b8b84686818329e9b3bd2184 http://xmlns.com/foaf/0.1/givenName A B
N2c6691b4a7174f6bbe8c0157f540c2bd http://purl.org/dc/terms/isPartOf http://id.crossref.org/issn/0036-8075
Nd89d1346b87c416c8629476ecceb0d0d http://www.w3.org/2000/01/rdf-schema#label medline11n0001
http://purl.org/okfn/medline/medline11n0001/12309 http://purl.org/net/opmv/ns#wasGeneratedBy Na794065ebdc64778959f76797a0a2e46
http://purl.org/okfn/medline/medline11n0001/1011 http://xmlns.com/foaf/0.1/primaryTopic http://www.ncbi.nlm.nih.gov/pubmed/16992022
http://purl.org/okfn/medline/medline11n0001/12676 http://purl.org/dc/terms/source PubMed-not-MEDLINE
N6cc4c37cdc6847178bad15aa82e19e24 http://www.w3.org/2006/time#inXSDDateTime 2011-05-08T14:40:58+00:00
http://www.ncbi.nlm.nih.gov/pubmed/17756165 http://purl.org/dc/terms/language eng
N965255d978e44d4c8c77cd59eb8b49a5 http://purl.org/net/opmv/ns#wasControlledBy http://river.styx.org/ww/foaf#me
http://purl.org/okfn/medline/medline11n0001/28849 http://purl.org/net/opmv/ns#wasGeneratedBy Nfef73030dbb543e08503f4701e67d447
http://www.ncbi.nlm.nih.gov/pubmed/17834253 http://purl.org/dc/terms/language eng
http://purl.org/okfn/medline/medline11n0001/13518 http://purl.org/dc/terms/source PubMed-not-MEDLINE
N8a8b891cdbd4470fb524dfc1eda7c6df http://purl.org/dc/terms/published 1886-31
N8c2ee5bf9cdd4dd4828ecfb17f78b0e8 http://xmlns.com/foaf/0.1/familyName Derby
http://www.ncbi.nlm.nih.gov/pubmed/17856285 http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://purl.org/ontology/bibo/AcademicArticle
http://purl.org/okfn/medline/medline11n0001/2529 http://purl.org/dc/terms/created 2007-02-07
N47e04e6821a94db98627cbb395e4a98e http://purl.org/dc/terms/published 1897
Ncddfc357b1b543ea947bc0d81916fa1a http://purl.org/dc/terms/published 1887
N52f5d235200849a69410b02f6a46c76a http://purl.org/net/opmv/ns#used Nb9d9b1c429404588816aef813740b2ad
http://www.ncbi.nlm.nih.gov/pubmed/17861840 http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://purl.org/ontology/bibo/AcademicArticle
http://www.ncbi.nlm.nih.gov/pubmed/17733304 http://purl.org/dc/terms/isPartOf N765d5350b3a94c0caa28ddf101e35069
N1229283449f04b1495125e9d352957c0 http://purl.org/ontology/bibo/volume 32
N6bb2c9f11dc44d8daa4c5b997f802b9c http://data.semanticweb.org/ns/swc/ontology#affiliation University of Dublin.
N026785fe08ad409c84958fdbb25dce85 http://purl.org/dc/terms/published 1900-06
N1e84dc56a6714856bc889bfc55f78e8e http://purl.org/dc/terms/isPartOf http://id.crossref.org/issn/0737-8769

In [20]:
g.parse(data, format="nquads")


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-20-30755f49d69b> in <module>()
----> 1 g.parse(data, format="nquads")

NameError: name 'data' is not defined

In [ ]: